from __future__ import unicode_literals, print_function

import config
import setting
from PySide2.QtGui import *
from PySide2.QtCore import *
from PySide2.QtWidgets import *
from maya.OpenMayaUI import *
from shiboken2 import wrapInstance

import connect_widget
import nodes_widget
import rename_widget
import setting_widget

class MainWindow(QWidget):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setParent(wrapInstance(int(MQtUtil.mainWindow()), QWidget))
        self.setWindowFlags(Qt.Window)

        self.setWindowTitle(" DG Editor {}".format(config.VERSION))

        self.main_layout = QVBoxLayout(self)
        self.main_layout.setContentsMargins(0,0,0,0)
        self.tab = QTabWidget(self)
        self.main_layout.addWidget(self.tab)
        self.tab.addTab(nodes_widget.new(), "节点")
        self.tab.addTab(connect_widget.new(), "连接")
        self.tab.addTab(rename_widget.new(), "名称")

        self.tab.addTab(setting_widget.new(), "设置")

        self.setting_font()

    def setting_font(self):
        fs = setting.get("font", None)
        if fs is None:
            fs =  QFont().toString()
        f = QFont()
        f.fromString(fs)
        self.setFont(f)



def new():
    win = MainWindow()
    win.show()

    if config.DEBUG:
        return win
